package models


type Direction struct {
	Model
	Title  string `json:"title"`
	Content string `json:"content"`
	I18N	string `json:"i18n" gorm:"column:i18n"`
	Show	int8   `json:"show"`
}


func ExistDirectionByID(id int) bool {
	var direction Direction
	db.Select("id").Where("id = ?", id).First(&direction)
	return direction.ID > 0
}

func GetDirections() (directions []Direction) {
	db.Find(&directions)
	return
}

func AddDirection(title, content, i18n string, show int8) bool {
	db.Create(&Direction{
		Title: title,
		Content: content,
		I18N: i18n,
		Show: show,
	})
	return true
}

func DeleteDirection(id int) bool {
	db.Where("id = ?", id).Delete(&Direction{})
	return true
}

func UpdateDirection(id int, data interface{}) bool {
	db.Model(&Direction{}).Where("id = ?", id).Updates(data)
	return true
}